﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SEO.Entity;
using System.Data;
using System.Data.SqlClient;


namespace SEO.Business
{
    /// <summary>
    /// 用户文章报表
    /// </summary>
    public class BisUserArticleReport
    {
       /// <summary>
        /// 删除报表
       /// </summary>
       /// <param name="dDayTime"></param>
       /// <returns></returns>
        public bool Delete(DateTime dDayTime)
        {
            return SqlHelper.ExecuteNonQuery(SqlHelper.database, CommandType.Text, "delete from [UserArticleReport] where [CreateTime]=@DayTime", new SqlParameter("@DayTime", dDayTime)) > 0;
        }

        /// <summary>
        /// 新增报表
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public bool Insert(UserArticleReport Info)
        {
            string strSql = "insert into [UserArticleReport]([AdminID],[OurWebCount],[OurWebUserCount],[NewsAllCount],[NewsAllSEOCount],[NewsCount1],[NewsCount2],[LinkAllCount],[LinkAllSEOCount],[LinkCount1],[LinkCount2],[CreateTime]) values(@AdminID,@OurWebCount,@OurWebUserCount,@NewsAllCount,@NewsAllSEOCount,@NewsCount1,@NewsCount2,@LinkAllCount,@LinkAllSEOCount,@LinkCount1,@LinkCount2,@CreateTime)";
            List<SqlParameter> parms = new List<SqlParameter>();
            parms.Add(new SqlParameter("@AdminID", Info.AdminID));
            parms.Add(new SqlParameter("@OurWebCount", Info.OurWebCount));
            parms.Add(new SqlParameter("@OurWebUserCount", Info.OurWebUserCount));
            parms.Add(new SqlParameter("@NewsAllCount", Info.NewsAllCount));
            parms.Add(new SqlParameter("@NewsAllSEOCount", Info.NewsAllSEOCount));
            parms.Add(new SqlParameter("@NewsCount1", Info.NewsCount1));
            parms.Add(new SqlParameter("@NewsCount2", Info.NewsCount2));
            parms.Add(new SqlParameter("@LinkAllCount", Info.LinkAllCount));
            parms.Add(new SqlParameter("@LinkAllSEOCount", Info.LinkAllSEOCount));
            parms.Add(new SqlParameter("@LinkCount1", Info.LinkCount1));
            parms.Add(new SqlParameter("@LinkCount2", Info.LinkCount2));
            parms.Add(new SqlParameter("@CreateTime", Info.CreateTime));
            return SqlHelper.ExecuteNonQuery(SqlHelper.database, CommandType.Text, strSql, parms.ToArray()) > 0;
        }

        /// <summary>
        /// 获取列表
        /// </summary>
        /// <param name="nAdminID"></param>
        /// <param name="dBeginTime"></param>
        /// <param name="dEndTime"></param>
        /// <returns></returns>
        public DataTable GetList(int nAdminID, DateTime dBeginTime, DateTime dEndTime)
        {
            string strSql = string.Empty;
            List<SqlParameter> parms = new List<SqlParameter>();
         
            if (nAdminID == 0)
            {
                strSql = "select Sum([OurWebCount]) [OurWebCount],Sum([OurWebUserCount]) [OurWebUserCount],Sum([NewsAllCount]) [NewsAllCount],Sum([NewsAllSEOCount]) [NewsAllSEOCount],Sum([NewsCount1]) [NewsCount1],Sum([NewsCount2]) [NewsCount2],Sum([LinkAllCount]) [LinkAllCount],Sum([LinkAllSEOCount]) [LinkAllSEOCount],Sum([LinkCount1]) [LinkCount1],Sum([LinkCount2]) [LinkCount2],convert(char(10),[CreateTime],23) [CreateTime] from [UserArticleReport] where [CreateTime] between @BeginTime and @EndTime group by [CreateTime] order by [CreateTime]";
            }
            else
            {
                parms.Add(new SqlParameter("@AdminID", nAdminID));
                strSql = "select [OurWebCount],[OurWebUserCount],[NewsAllCount],[NewsAllSEOCount],[NewsCount1],[NewsCount2],[LinkAllCount],[LinkAllSEOCount],[LinkCount1],[LinkCount2],convert(char(10),[CreateTime],23) [CreateTime] from [UserArticleReport] where [AdminID]=@AdminID and [CreateTime] between @BeginTime and @EndTime order by [CreateTime]";
            }
            parms.Add(new SqlParameter("@BeginTime", dBeginTime));
            parms.Add(new SqlParameter("@EndTime", dEndTime));
            return SqlHelper.ExecuteDataset(SqlHelper.database, CommandType.Text, strSql, parms.ToArray()).Tables[0];
           
        }
    }
}
